package com.sx.zongzhi.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sx.zongzhi.BaseActivity;
import com.sx.zongzhi.R;
import com.sx.zongzhi.adapter.PictureAdapter;
import com.sx.zongzhi.bean.PhotoBean;
import com.sx.zongzhi.bean.ServiceRecordDetailBean;
import com.sx.zongzhi.presenter.ServiceRecordDetailPest;
import com.sx.zongzhi.utils.ToastUtils;
import com.sx.zongzhi.view.IServiceRecordDetailView;
import com.sx.zongzhi.widget.LoadDialog;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 服务记录详情
 */
public class ServiceRecordDetailActivity extends BaseActivity implements IServiceRecordDetailView{

    @BindView(R.id.tv_Time)
    TextView tv_Time;
    @BindView(R.id.tv_ServiceLocal)
    TextView tv_ServiceLocal;
    @BindView(R.id.tv_Worker)
    TextView tv_Worker;
    @BindView(R.id.tv_OtherWorker)
    TextView tv_OtherWorker;
    @BindView(R.id.tv_WorkerObject)
    TextView tv_WorkerObject;
    @BindView(R.id.tv_ServiceContent)
    TextView tv_ServiceContent;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private String serviceRecordID="";

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_serice_record_detial);
        setTitleName("服务记录详情");
        serviceRecordID=getIntent().getStringExtra("ServiceRecordDetailId");
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        LoadDialog.show(this);
        ServiceRecordDetailPest recordDetailPest=new ServiceRecordDetailPest(this);
        recordDetailPest.getServiceRecordDetail(serviceRecordID);
    }


    private void initView(List<PhotoBean> photos) {

        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayout.HORIZONTAL, false));
        PictureAdapter pictureAdapter = new PictureAdapter(this, photos);
        recyclerView.setAdapter(pictureAdapter);
        pictureAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            }
        });
    }

    @Override
    public void showError(String message) {
        LoadDialog.dismiss(this);
        ToastUtils.showToast(this,message);
    }

    @Override
    public void getServiceRecordDetail(ServiceRecordDetailBean detailBean) {
        LoadDialog.dismiss(this);
        if(detailBean!=null){
            tv_Time.setText(detailBean.getOccurDate());
            tv_ServiceLocal.setText(detailBean.getOccurPlace());
            tv_Worker.setText(detailBean.getServiceMembers());
            tv_WorkerObject.setText(detailBean.getServiceObjects());
            tv_OtherWorker.setText(detailBean.getServiceJoiners());
            tv_ServiceContent.setText(detailBean.getServiceContent());
            if (detailBean.getFiles()!=null&&detailBean.getFiles().size()>0){
                initView(detailBean.getFiles());
            }
        }else {
            ToastUtils.showToast(this,"服务器异常 请稍后再试");
        }
    }
}
